Skip to content

Rustify ci/integration.sh script#6817

Open
GuillaumeGomez wants to merge 5 commits intorust-lang:mainfrom
GuillaumeGomez:rustify-shell
Open

Rustify ci/integration.sh script#6817
GuillaumeGomez wants to merge 5 commits intorust-lang:mainfrom
GuillaumeGomez:rustify-shell

Conversation

@GuillaumeGomez
Copy link
Member

As discussed on zulip.

I went the easy road: didn't create a workspace for this script, so it uses the same dependencies as the main project (although it only needs std). It can be run with cargo run --bin ci-integration.

Anyway, this is very straightforward conversion, please tell me if you'd prefer things to be different in any regard.

r? @jieyouxu

@rustbot rustbot added A-CI Area: CI S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Mar 4, 2026
Copy link

@matthewhughes934 matthewhughes934 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my style comments are subjective, so feel free to ignore at your discretion

View changes since this review

Comment on lines +173 to +183
// FIXME: this means we can get a stale cargo-fmt from a previous run.
//
// `which rustfmt` fails if rustfmt is not found. Since we don't install
// `rustfmt` via `rustup`, this is the case unless we manually install it. Once
// that happens, `cargo install --force` will be called, which installs
// `rustfmt`, `cargo-fmt`, etc to `~/.cargo/bin`. This directory is cached by
// travis (see `.travis.yml`'s "cache" key), such that build-bots that arrive
// here after the first installation will find `rustfmt` and won't need to build
// it again.
//
//which cargo-fmt || cargo install --force

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment outdated now: do things still run in Travis? Does Github actions have the same caching that might cause an issue here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely no idea. I kept the existing comments as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this, as far as I know rust-lang/* CI has not been using Travis for a good while.

Would be good if one of the maintainers can double-check.

In the GHA case this is only true if we explicitly opt-in to actions cache on ~/.cargo/bin, i.e.

https://github.com/actions/cache/blob/main/examples.md#rust---cargo

Looking at https://github.com/rust-lang/rustfmt/blob/main/.github/workflows/integration.yml we don't use any caching so this should be fine.

}

let output = run_command_with_output_and_env("cargo", &["test", test_args], current_dir, &env)?;
if ["build failed", "test result: FAILED."]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we get here? If tests or builds fail I assume cargo test will exit non-zero and in that case will run_command_with_output_and_env above return an Err?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the same behaviour as before: https://github.com/rust-lang/rustfmt/blob/main/ci/integration.sh#L46-L48

If the output contains one of the two strings, we return the function with 0, meaning success. Sounds super weird but that's the current behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, run_command_with_output_and_env doesn't check whether or not the command exited successfully.

Copy link
Member

@jieyouxu jieyouxu Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that the intention there is to skip over crates which already fails test (if the baseline fails it could be other reasons too).

This comment was marked as resolved.

)?;
write_file("rustfmt_check_output", &output)?;

run_command_with_env("cargo", &["test", test_args], current_dir, &env)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we already run cargo test at line 118?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might catch really broken --check format where it should not have modified the source in some off chance, seems okay to keep it. Can we add a comment here to say sth to that effect? I imagine we won't be the only ones with that question reading this :)

@GuillaumeGomez
Copy link
Member Author

Applied suggestions and fixed file creation.

Copy link

@matthewhughes934 matthewhughes934 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I didn't read the original script carefully enough on my first review (I think most my confusion comes from things that script was already doing, sorry about that). So this review is more focused on changes in behaviour from the old script

(also Github isn't letting me resolve some of the conversations your answered? I don't see the button for it for some reason)

View changes since this review

@GuillaumeGomez
Copy link
Member Author

Updated!

@GuillaumeGomez
Copy link
Member Author

Applied suggestion.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. This broadly looks good to me, some nits.
@rustbot author

View changes since this review

INTEGRATION: ${{ matrix.integration }}
TARGET: x86_64-unknown-linux-gnu
run: ./ci/integration.sh
run: cargo run --bin ci-integration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark (not for this PR): I wonder if we should coalsce this and Diff Check into one crate, sth akin to citool on r-l/r. The benefit is that the tools could then share common logic easily.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I plan to do. But to reduce the diff, I decided to do it in multiple parts:

  1. Migrate shell scripts to rust
  2. Improve code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I think I'll make one crate once I start porting the second one to not duplicate code.

bin: &str,
args: I,
current_dir: &str,
env: &HashMap<&str, &str>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: thought about BTreeMap for stable iteration order but I think that might not matter

}

let output = run_command_with_output_and_env("cargo", &["test", test_args], current_dir, &env)?;
if ["build failed", "test result: FAILED."]
Copy link
Member

@jieyouxu jieyouxu Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that the intention there is to skip over crates which already fails test (if the baseline fails it could be other reasons too).


let output =
run_command_with_output_and_env("cargo", &["fmt", "--all", "-v"], current_dir, &env)?;
println!("{}", output.output);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought (not for this PR): we might be able to help group the logs with GHA log groups

)?;
write_file("rustfmt_check_output", &output)?;

run_command_with_env("cargo", &["test", test_args], current_dir, &env)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might catch really broken --check format where it should not have modified the source in some off chance, seems okay to keep it. Can we add a comment here to say sth to that effect? I imagine we won't be the only ones with that question reading this :)

Comment on lines +173 to +183
// FIXME: this means we can get a stale cargo-fmt from a previous run.
//
// `which rustfmt` fails if rustfmt is not found. Since we don't install
// `rustfmt` via `rustup`, this is the case unless we manually install it. Once
// that happens, `cargo install --force` will be called, which installs
// `rustfmt`, `cargo-fmt`, etc to `~/.cargo/bin`. This directory is cached by
// travis (see `.travis.yml`'s "cache" key), such that build-bots that arrive
// here after the first installation will find `rustfmt` and won't need to build
// it again.
//
//which cargo-fmt || cargo install --force
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this, as far as I know rust-lang/* CI has not been using Travis for a good while.

Would be good if one of the maintainers can double-check.

In the GHA case this is only true if we explicitly opt-in to actions cache on ~/.cargo/bin, i.e.

https://github.com/actions/cache/blob/main/examples.md#rust---cargo

Looking at https://github.com/rust-lang/rustfmt/blob/main/.github/workflows/integration.yml we don't use any caching so this should be fine.

@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Mar 10, 2026
@GuillaumeGomez
Copy link
Member Author

Applied suggestions, I also added comments to explain the final command as well.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me with one tiny nit, thanks

View changes since this review

Cargo.toml Outdated
Comment on lines +74 to +76
[[bin]]
name = "ci-integration"
path = "ci/integration.rs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we move this up to be alongside the other [[bin]]s?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CI Area: CI S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants